﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Weazel.Toad.Application.Actions
{
	class InsertDatapathFsmSkeletonAction : ActionBase
	{
		private const string skeleton =
			"dp mydp {\n" +
			"  sfg run {\n" +
			"  }\n" +
			"}\n" +
			"\n" +
			"fsm ctrl(mydp) {\n" +
			"	initial s0;\n" +
			" @s0 run -> s0;\n" +
			"}\n";

		public InsertDatapathFsmSkeletonAction()
		{
      Enabled = false;

      Application.Instance.SelectedItemChanged +=
        new EventHandler<SelectedItemChangedEventArgs>(Instance_SelectedItemChanged);
		}

		public override void Execute(object sender, EventArgs e)
		{
			if (Application.Instance.SelectedItem is Items.GezelTextFile)
			{
				Items.GezelTextFile file =
					Application.Instance.SelectedItem as Items.GezelTextFile;

				file.TextEditor.TextAreaControl.TextArea.InsertString(skeleton);
			}
		}

    void Instance_SelectedItemChanged(object sender, SelectedItemChangedEventArgs e)
    {
      if (e.SelectedItem is Items.GezelTextFile)
      {
        Enabled = true;
      }
      else
      {
        Enabled = false;
      }
    }
	}
}
